//
//  FtBusinessInformationController.m
//  Feast
//
//  Created by 胡光健 on 2017/8/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FtBusinessInformationController.h"
#import "FtToApplyForCell.h"
#import "FtEditInformationController.h"

@interface FtBusinessInformationController ()
@property(nonatomic,strong)NSArray * textArr;
@property(nonatomic,strong)NSMutableArray * textDetailArr;
@end

@implementation FtBusinessInformationController
-(NSArray *)textArr {
    if (!_textArr) {
        _textArr = @[@"商户编号",@"商户名",@"商户负责人",@"联系电话",@"商户类型"];
    }
    return _textArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _textDetailArr = [NSMutableArray array];
    NSArray * arr = @[@"SJ001",@"XX商家",@"阳永江",@"15762536368",@"甜品"];
    _textDetailArr = [arr mutableCopy];
    [self configButton];
}

-(void)configTableView {
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    [self.tableView registerCellByNibName:@"FtToApplyForCell"];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.textArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FtToApplyForCell * cell = [tableView dequeueReusableCellWithIdentifier:@"FtToApplyForCell"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleLabel.text = self.textArr[indexPath.row];
    cell.contetLabel.text = self.textDetailArr[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self pushEditInformationWithRow:indexPath.row];
}

-(void)pushEditInformationWithRow:(NSUInteger)row {
    WeakSelf
    FtEditInformationController *vc =[[FtEditInformationController alloc]init];
    if (row ==0) {
        vc.type = MerchantCode;
        vc.navTitle = @"商户编号";
    }else if (row ==1) {
        vc.type = BusinessName;
        vc.navTitle = @"商户名";
    }else if (row ==2) {
        vc.type = BusinessPeople;
        vc.navTitle = @"商户负责人";
    }else if (row ==3) {
        vc.type = BusinessTell;
        vc.navTitle = @"联系电话";
    }else {
        vc.type = BusinessType;
        vc.navTitle = @"商户类型";
    }
    vc.textFieldStrBlock = ^(NSString *text, EditinformationType type) {
        [weakSelf replaceTableWithCellReload:row text:text type:type];
    };
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)replaceTableWithCellReload:(NSUInteger)row text:(NSString *)text type:(EditinformationType)type {
    [_textDetailArr replaceObjectAtIndex:row withObject:text];
    [self.tableView reloadRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] withRowAnimation:UITableViewRowAnimationNone];
//    [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathWithIndex:row]] withRowAnimation:UITableViewRowAnimationNone];
    
}

-(void)configButton {
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.bounds = CGRectMake(0, 0, 160, 34);
    btn.center = CGPointMake(self.view.centerX, self.view.centerY +80);
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn setBackgroundImage:HJImage(@"按钮") forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(okButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    [self.view bringSubviewToFront:btn];
}

-(void)okButtonClicked {
    
}
@end
